import Layout1 from './views/layout/layout'; 
import Login from './views/login/login';
import Mine from './views/mine/mine';
import Register from './views/register/register';
import Administrator from "./views/Administrator/administrator";
import {BrowserRouter,Route,Routes} from 'react-router-dom'
import { Outlet } from 'react-router-dom';
import OtherMine from './views/othermine/orhermine';
import Square from './views/square/square';
import AdminiLayout from "./views/AdminiLayout/adminiLayout";
import { createStore ,combineReducers} from 'redux';
import {Provider } from 'react-redux'
import LayoutContainer from "./views/layout/layout";
import SquareContainer from "./views/square/square";
function App() {
  // 定义action类型
  const UPDATE_ACTIVE_BUTTON = 'UPDATE_ACTIVE_BUTTON';
  const UPDATE_ACTIVE_BUTTON1    ='UPDATE_ACTIVE_BUTTON1';
  const UPDATE_SEARCH='UPDATE_SEARCH';
  const UPDATE_SEARCH_STATUS='UPDATE_SEARCH_STATUS';
  // 创建reducer来更新状态
  const layoutReducer = (state = { activeButton: 'button1' }, action) => {
    if (action.type === UPDATE_ACTIVE_BUTTON) {
      return {
        ...state,
        activeButton: action.payload
      };
    }
    return state;
  };
  const layoutReducer1 = (state = { activeButton6: 1}, action) => {
    if (action.type === UPDATE_ACTIVE_BUTTON1) {
      return {
        ...state,
        activeButton6: action.payload
      };
    }
    return state;
  };
  const layoutReducer2 = (state = { search: ''}, action) => {
    if (action.type === UPDATE_SEARCH) {
      return {
        ...state,
        search: action.payload
      };
    }
    return state;
  };
  const layoutReducer3 = (state = { searchstatus: false}, action) => {
    if (action.type === UPDATE_SEARCH_STATUS) {
      return {
        ...state,
        searchstatus: action.payload
      };
    }
    return state;
  };
  // 合并 reducer
  const rootReducer = combineReducers({
    reducer1Data: layoutReducer,
    reducer2Data:layoutReducer1,
    reducer3Data:layoutReducer2,
    reducer4Data:layoutReducer3,
  });
  // 创建store并传入reducer
  const store = createStore(rootReducer);
  return (
    <>
      <Provider store={store}>
    <BrowserRouter>  
    <Routes>
      <Route path='/' element={<Login/>}/>
      <Route path='/register' element={<Register/>}/>
      <Route path='/administrator' element={<Administrator/>}/>
      <Route path='/adminilayout' element={<AdminiLayout/>}/>
      <Route path='/layout' element={<LayoutContainer/>}>
        <Route path='mine' element={<Mine/>}/>
        <Route path='square' element={<SquareContainer />}/>
        <Route path='othermine/:studentId' element={<OtherMine/>}/>
      </Route>
    </Routes>
    </BrowserRouter>
    </Provider>
    <Outlet />
    </>
  );
}

export default App;
